﻿using First_WebAPI.Commons;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace First_WebAPI.Filters
{
    public class ExceptionFilter : IAsyncExceptionFilter
    {
        public Task OnExceptionAsync(ExceptionContext context)
        {
            //返回给前台的信息，可以包装一下，捕获所有异常，避免每个接口都try catch
            ObjectResult objectResult = new ObjectResult(new ResponseResult { Code = 500, Message = "系统繁忙" });
            context.Result = objectResult;
            return Task.CompletedTask;
        }
    }
}
